package com.lyx.db137.controller;

import com.lyx.db137.common.R;
import com.lyx.db137.entity.Role;
import com.lyx.db137.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: zero domain
 * @CreateTime: 2024/12/31 10:07
 * @Description: TODO
 * @Version: 1.0
 */
@CrossOrigin(origins = "*")
@RestController
public class RoleController {
    @Autowired
    RoleService roleService;

    /**
     * 获取所有角色集合
     * @return
     */
    @GetMapping("selectRole")
    public R selectRole(){
        List<Role>  rolelist = this.roleService.list();
        return new R().add("rolelist",rolelist);
    }

    /**
     * 根据用户id获取拥有的角色集合
     * @param userid
     * @return
     */
    @GetMapping("selectRoleByUserId/{userid}")
    public R selectRoleByUserId(@PathVariable("userid")int userid){
        List<Role> roleList= this.roleService.selectRoleByUserId(userid);
        return new R().add("roleList",roleList);
    }

}
